package com.zaofan.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.zaofan.bean.UserFollow;
import com.zaofan.constant.UrlConstant;
import com.zaofan.dao.base.DaoSupportImpl;

public class UserFollowDao extends DaoSupportImpl<UserFollow> {

	public List<com.zaofan.mobile.bean.UserFollow> getUserFans(Integer userId, String begin, String end) {
		try {
			String sql = "select userfollow.*,account.nickName as name,concat('" + UrlConstant.HOST_URL
					+ "',account.photo) as photo from userfollow,account where userfollow.otherId = " + userId
					+ " and userfollow.userId = account.id " + " order by userfollow.addTime desc limit " + begin + ","
					+ end;
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new BeanListHandler<>(com.zaofan.mobile.bean.UserFollow.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<com.zaofan.mobile.bean.UserFollow> getUserFollow(Integer userId, String begin, String end) {
		try {
			String sql = "select userfollow.*,account.nickName as name,concat('" + UrlConstant.HOST_URL
					+ "',account.photo) as photo from userfollow,account where userfollow.userId = " + userId
					+ " and userfollow.otherId = account.id " + " order by userfollow.addTime desc limit " + begin + ","
					+ end;
			System.err.println(sql);
			QueryRunner runner = new QueryRunner(getDataSource());
			return runner.query(sql, new BeanListHandler<>(com.zaofan.mobile.bean.UserFollow.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

}
